<template>
  <w-pickbox :picker="picker">
    <w-tree :current="focusLeafs" :pub="treePub">
      <w-leaf key="root" :expanded="true" :folder="true" template="task/TaskLeaf" :data="treeList"></w-leaf>
    </w-tree>
  </w-pickbox>
</template>

<script>
  import $ from '../../dfish.js'

  export default {
    props: ['modelValue'],
    watch: {
      modelValue(v) {
        //$(this).val(this.modelValue)
      }
    },
    data() {
      return {
        loaded: false,
        focusLeafs: null,
        treePub: {
          on: {
            click: this.clickLeaf
          }
        },
        treeList: {
          id: '100',
          icon: '.f-i-qq',
          text: '福建省',
          expanded: true,
          children: [{
              id: '110',
              text: '福州市福州市福州市福州市福州市福州市福州市福州市福州市福州市福州市福州市',
              children: [{
                  id: '111',
                  text: '鼓楼区'
                },
                {
                  id: '112',
                  text: '晋安区'
                },
              ]
            },
            { id: '120', text: '厦门市' },
            { id: '120', text: '厦门市' },
            { id: '120', text: '厦门市' },
            { id: '120', text: '厦门市' },
            { id: '120', text: '厦门市' },
            { id: '120', text: '厦门市' },
            { id: '120', text: '厦门市' },
            { id: '120', text: '厦门市' },
            { id: '120', text: '厦门市' },
            { id: '120', text: '厦门市' },
            { id: '120', text: '厦门市' },
            { id: '120', text: '厦门市' },
            { id: '120', text: '厦门市' },
            { id: '120', text: '厦门市' },
            { id: '120', text: '厦门市' },
            { id: '120', text: '厦门市' },
            { id: '120', text: '厦门市' },
            { id: '120', text: '厦门市' },
            { id: '120', text: '厦门市' },
            { id: '120', text: '厦门市' },
            { id: '120', text: '厦门市' },
            { id: '120', text: '厦门市' },
            { id: '120', text: '厦门市' },
            { id: '120', text: '厦门市' },
            { id: '120', text: '厦门市' },
            { id: '120', text: '厦门市' },
            { id: '120', text: '厦门市' },
            { id: '120', text: '厦门市' },
            { id: '120', text: '厦门市' },
            { id: '120', text: '厦门市' },
            { id: '120', text: '厦门市' },
            { id: '120', text: '厦门市' },
            { id: '120', text: '厦门市' },
            { id: '120', text: '厦门市' },
            { id: '120', text: '厦门市' },
            { id: '120', text: '厦门市' },
            { id: '120', text: '厦门市' },
            { id: '120', text: '厦门市' },
            { id: '120', text: '厦门市' },
            { id: '120', text: '厦门市' },
          ]
        }
      }
    },
    mounted() {
      $(this).val([])
      $(this).saveModified()
    },
    methods: {
      picker() {
        $(this).cmd({
          type: 'Dialog',
          template: 'task/TaskForm',
          preload: 'DialogStd',
          class: 'large',
        }, '001')
      },
      clickLeaf(e) {
        let d = $(e).data
        this.focusLeafs = [{
          id: d.id
        }]
        $(this).val([{
          value: d.id,
          text: d.text
        }])
        //$(this).wrapper.$emit('update:modelValue', [{value: d.id, text: d.text}, {value: 'ccc', text: 'ccc'}])
        $.close(e)
      }
    }
  }
</script>
